ARG BASE_IMAGE=swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nvidia/cuda:12.6.1-cudnn-devel-ubuntu22.04
ARG ENV_IMAGE=env-image

FROM ${BASE_IMAGE} AS env-image
WORKDIR /workspace
COPY requirements.txt .

RUN sed -i 's/security.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
RUN apt update && apt install -y build-essential curl vim git wget fontconfig libicu-dev

ENV PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
RUN apt update && apt install -y python3 python3-pip python3-venv
RUN python3 -m venv /opt/venv
RUN /opt/venv/bin/pip install --upgrade pip
RUN /opt/venv/bin/pip install -r requirements.txt
ENV PATH="/opt/venv/bin:$PATH"

FROM ${ENV_IMAGE} AS app-image
ARG APP_ROOT=/data/project/Intelligent-Review-Backend
ARG FLASK_APP=src/main.py

RUN mkdir -p ${APP_ROOT}
COPY . ${APP_ROOT}
WORKDIR ${APP_ROOT}/src

ENV PYTHONPATH=${APP_ROOT}
ENV APP_PATH=${APP_ROOT}
ENV FLASK_APP=${FLASK_APP}

EXPOSE 6006
#ENTRYPOINT ["flask", "run", "--host=0.0.0.0", "--port=6009"]
# deploy web server using uwsgi module
ENTRYPOINT ["uwsgi", "--ini", "uwsgi.ini"]
